home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 10.0 KB | 386 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: TextFacet.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Anthone Burbidge
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- // ----- TextPart Includes -----
-
- #ifndef _TEXTUTIL_
- #include "TextUtil.h"
- #endif
-
- #ifndef _TEXTFACET_
- #include "TextFacet.h"
- #endif
-
- #ifndef _TEXTFRAME_
- #include "TextFrame.h"
- #endif
-
- #ifndef _TEXTPART_
- #include "TextPart.h"
- #endif
-
- #ifndef _RULERFRAME_
- #include "RulerFrame.h"
- #endif
-
- #ifndef _TEXTSELC_
- #include "TextSelc.h"
- #endif
-
- #ifndef _ODTEXT_
- #include "ODText.h"
- #endif
-
- // ----- Textension Includes -----
-
- #ifndef _Textension_
- #include "Textension.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWFRAME_H
- #include <FWFrame.h>
- #endif
-
- #ifndef FWRECT_H
- #include <FWRect.h>
- #endif
-
- #ifndef FWUTIL_H
- #include <FWUtil.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _TRNSFORM_
- #include <Trnsform.h>
- #endif
-
- #ifndef _DRAGDROP_
- #include <DragDrop.h>
- #endif
-
- #ifndef _STDPROPS_
- #include <StdProps.h>
- #endif
-
- #ifndef _STDTYPES_
- #include <StdTypes.h>
- #endif
-
- #ifndef _DGITMITR_
- #include <DgItmItr.h>
- #endif
-
- #ifndef _TRANSLAM_
- #include <TranslaM.h>
- #endif
-
- #ifndef _XMPSESSM_
- #include <XMPSessM.h>
- #endif
-
- // ----- Macintosh Includes -----
-
- #ifndef __FIXMATH__
- #include <FixMath.h>
- #endif
-
- #ifndef mathRoutinesIncludes
- #include <Math Routines.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #pragma segment TextPartSegment
-
- //========================================================================================
- // CLASS CTextFacet
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::CTextFacet
- //----------------------------------------------------------------------------------------
-
- CTextFacet::CTextFacet() :
- FW_CFacet(),
- fTextPart(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::InitTextFacet
- //----------------------------------------------------------------------------------------
-
- void CTextFacet::InitTextFacet(XMPFacet* facet, CTextPart* textPart)
- {
- InitFacet(facet);
- fTextPart = textPart;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::~CTextFacet
- //----------------------------------------------------------------------------------------
-
- CTextFacet::~CTextFacet()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::Draw
- //----------------------------------------------------------------------------------------
-
- void CTextFacet::Draw(FW_CGraphicContext *gc)
- {
- XMPShape* clipShape = ::NewXMPShape();
- gc->GetClipShape(clipShape);
-
- ::EraseRgn(clipShape->GetQDRegion());
-
- CTextDrawInitiator di(this);
-
- FW_SPlatformRect bounds = (**clipShape->GetQDRegion()).rgnBBox;
-
- fTextPart->SetEmbeddedRunFrame((CTextFrame *) GetFrame());
- fTextPart->SetEmbeddedRunFacet(this);
-
- (fTextPart->GetEditText())->Draw(&bounds, kNoDrawFlags);
-
- delete clipShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTextFacet::DoMouseDown(const FW_CPoint& where,
- XMPEventData event)
- {
- FW_UNUSED(where);
-
- CTextDrawInitiator di(this);
-
- EventRecord localEvent = *event;
-
- FW_CRect sbBounds;
-
- fTextPart->SetEmbeddedRunFrame((CTextFrame *) GetFrame());
- fTextPart->SetEmbeddedRunFacet(this);
- fTextPart->SetEmbeddedRunEvent(event);
-
- // The following statement delegates the responsibility of dragging to an embedded
- // part if the selection consists solely of the part. This gives us a chance to see
- // if the mouse is in the resize handle.
-
- FW_Boolean didDrag = FALSE;
- if (((CTextSelection *) fTextPart->GetSelection())->IsPointInSelection(where)
- && !((CTextSelection *) fTextPart->GetSelection())->IsSelectionOnlyOneProxyRun())
- didDrag = fTextPart->GetSelection()->Drag(this, event);
-
- if (!didDrag)
- {
- TClickCommandInfo clickCommandInfo;
- (fTextPart->GetEditText())->Click(&localEvent, &clickCommandInfo, NULL, NULL);
- }
-
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::MouseEnter
- //----------------------------------------------------------------------------------------
-
- void CTextFacet::MouseEnter(const FW_CPoint& where)
- {
- FW_UNUSED(where);
- SetCursor(*GetCursor(iBeamCursor));
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::NewDropTracker
- //----------------------------------------------------------------------------------------
-
- FW_CDropTracker* CTextFacet::NewDropTracker(FW_CFacet* facet)
- {
- CTextDropTracker* dropTracker = new CTextDropTracker;
- dropTracker->InitTextDropTracker((CTextFacet *) facet);
- return dropTracker;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::DragEnter
- //----------------------------------------------------------------------------------------
-
- void CTextFacet::DragEnter(XMPDragItemIterator* dragInfo, const FW_CPoint& where)
- {
- FW_CFacet::DragEnter(dragInfo, where);
-
- if (!this->GetCanAcceptDrop())
- {
- XMPStorageUnit *dragSU;
-
- XMPTranslation *translate = GetFrame()->GetPart()->GetSession()->GetTranslation();
- XMPType kAppleTEXT = translate->GetISOTypeFromPlatformType('TEXT', kXMPPlatformDataType);
-
- for (dragSU = dragInfo->First(); dragSU; dragSU = dragInfo->Next())
- if (dragSU->Exists(kXMPPropContents, kAppleTEXT, 0))
- this->SetCanAcceptDrop(TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFacet::DrawDragHiliteInside
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTextFacet::DrawDragHiliteInside()
- {
- return FALSE;
- }
-
-
- //========================================================================================
- // CLASS CTextDropTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::CTextDropTracker
- //----------------------------------------------------------------------------------------
-
- CTextDropTracker::CTextDropTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::~CTextDropTracker
- //----------------------------------------------------------------------------------------
-
- CTextDropTracker::~CTextDropTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::InitTextDropTracker
- //----------------------------------------------------------------------------------------
-
- void CTextDropTracker::InitTextDropTracker(CTextFacet* facet)
- {
- FW_CDropTracker::InitDropTracker(facet);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- void CTextDropTracker::BeginTracking(const FW_CPoint& where)
- {
- #if 0
- char str[80];
- sprintf(str, (const char *) "\pBeginTracking: where=(%d,%d)\n", FixedToInt(where.x), FixedToInt(where.y));
- SysBreakFunc((unsigned const char *) str);
- #endif
-
- fCharOffset = this->GetCharOffset(where);
- this->DrawCaret(fCharOffset);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::ContinueTracking
- //----------------------------------------------------------------------------------------
-
- void CTextDropTracker::ContinueTracking(const FW_CPoint& where)
- {
- TOffset newOffset = this->GetCharOffset(where);
- if (newOffset != fCharOffset)
- {
- #if 0
- char str[80];
- sprintf(str, (const char *) "\pContinueTracking: where=(%d,%d)\n", FixedToInt(where.x), FixedToInt(where.y));
- SysBreakFunc((unsigned const char *) str);
- #endif
-
- this->DrawCaret(fCharOffset);
- this->DrawCaret(newOffset);
- fCharOffset = newOffset;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::EndTracking
- //----------------------------------------------------------------------------------------
-
- void CTextDropTracker::EndTracking(const FW_CPoint& where)
- {
- FW_UNUSED(where);
-
- #if 0
- char str[80];
- sprintf(str, (const char *) "\pEndTracking: where=(%d,%d)\n", FixedToInt(where.x), FixedToInt(where.y));
- SysBreakFunc((unsigned const char *) str);
- #endif
-
- this->DrawCaret(fCharOffset);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::GetCharOffset
- //----------------------------------------------------------------------------------------
-
- TOffset CTextDropTracker::GetCharOffset(const FW_CPoint& where) const
- {
- TOffsetRange range;
- Boolean outside;
-
- FW_SPlatformPoint pt;
- where.AsPlatformPoint(pt);
-
- this->GetTextPart()->GetEditText()->Point2Char(pt, &range, &outside);
-
- return range.Start();
- }
-
- //----------------------------------------------------------------------------------------
- // CTextDropTracker::DrawCaret
- //----------------------------------------------------------------------------------------
-
- void CTextDropTracker::DrawCaret(TOffset charOffset)
- {
- #if 0
- char str[80];
- sprintf(str, (const char *) "\pDrawCaret: offset=%ld\n", charOffset.offset);
- SysBreakFunc((unsigned const char *) str);
- #endif
-
- short hite;
- long top, trailEdge;
-
- this->GetTextPart()->GetEditText()->Char2Point(charOffset, &top, &trailEdge, &hite);
-
- PenMode(patXor);
-
- ::MoveTo((short) trailEdge, (short) top);
- ::Line(0, hite);
-
- PenNormal();
- }
-
-